/*
 * frmAgregarJugadores2.java
 *
 * Created on 9 de septiembre de 2007, 11:03 PM
 */
package prototipo;

import BE.jugador;
import BE.partida;
import BE.torneo;
import BL.partidaBL;
//import com.sun.imageio.plugins.png.RowFilter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Vector;
import java.util.regex.PatternSyntaxException;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableRowSorter;
import ajedrezLogica.frmLecturaPartidas;

/**
 *
 * @author  Billy
 */
public class frmBuscarPartidas extends javax.swing.JInternalFrame {

    jugador unJugador, jugadorBlancas, jugadorNegras;
    DefaultTableModel dtm;
    TableRowSorter sorter;
    String text;
    torneo miTorneo;
    int codDivision, fila, idPartidaElegida;
    partidaBL pBL;
    ArrayList<partida> arrPartidas;
    JDesktopPane jDesktopPane1;
    partida unaPartida;

    /** Creates new form frmAgregarJugadores2 */
    public frmBuscarPartidas(JDesktopPane jDesktopPane1) {

        initComponents();
        this.btnVerPartida.setEnabled(false);
        this.jDesktopPane1 = jDesktopPane1;

        this.txtFiltro.getDocument().addDocumentListener(new DocumentListener() {

            public void insertUpdate(DocumentEvent evt) {
                searchFieldChangedUpdate(evt);
            }

            public void removeUpdate(DocumentEvent evt) {
                searchFieldChangedUpdate(evt);
            }

            public void changedUpdate(DocumentEvent evt) {
                searchFieldChangedUpdate(evt);
            }
        });

        pBL = new partidaBL();
        this.llenarGrillaPartidas();
        unaPartida = new partida();

        this.btnBlancas.setEnabled(false);
        this.btnNegras.setEnabled(false);
        this.btnTorneo.setEnabled(false);
        this.btnActualizarPartida.setEnabled(false);

        ButtonGroup grupodeBotones = new ButtonGroup();
        grupodeBotones.add(this.rbtBlancas);
        grupodeBotones.add(this.rbtNegras);
        grupodeBotones.add(this.rbtTablas);
        this.rbtBlancas.setSelected(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblPartidas = new javax.swing.JTable();
        jLabel9 = new javax.swing.JLabel();
        txtFiltro = new javax.swing.JTextField();
        pnlInscripcion = new javax.swing.JPanel();
        btnVerPartida = new javax.swing.JButton();
        btnActualizarDatos = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        txtJugadorBlancas = new javax.swing.JTextField();
        txtJugadorNegras = new javax.swing.JTextField();
        txtNombreTorneo = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtpMovimientos = new javax.swing.JTextPane();
        lblMovimientos = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jdcFechaJuego = new com.toedter.calendar.JDateChooser();
        jLabel8 = new javax.swing.JLabel();
        rbtBlancas = new javax.swing.JRadioButton();
        rbtNegras = new javax.swing.JRadioButton();
        lblSexo = new javax.swing.JLabel();
        btnActualizarPartida = new javax.swing.JButton();
        btnLimpiar = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        rbtTablas = new javax.swing.JRadioButton();
        btnBlancas = new javax.swing.JButton();
        btnNegras = new javax.swing.JButton();
        btnTorneo = new javax.swing.JButton();
        btnSalir = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setTitle("Buscar Partidas");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        tblPartidas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "Id Partida", "Fecha", "Blancas", "Negras", "Torneo", "Resultado"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        tblPartidas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblPartidasMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tblPartidas);

        jLabel9.setText("Partida a Buscar");

        pnlInscripcion.setBorder(javax.swing.BorderFactory.createTitledBorder("Ver Partida"));

        btnVerPartida.setText("Ver Partida");
        btnVerPartida.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVerPartidaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlInscripcionLayout = new javax.swing.GroupLayout(pnlInscripcion);
        pnlInscripcion.setLayout(pnlInscripcionLayout);
        pnlInscripcionLayout.setHorizontalGroup(
            pnlInscripcionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlInscripcionLayout.createSequentialGroup()
                .addGap(94, 94, 94)
                .addComponent(btnVerPartida)
                .addContainerGap(109, Short.MAX_VALUE))
        );
        pnlInscripcionLayout.setVerticalGroup(
            pnlInscripcionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlInscripcionLayout.createSequentialGroup()
                .addComponent(btnVerPartida)
                .addContainerGap(11, Short.MAX_VALUE))
        );

        btnActualizarDatos.setText("Actualizar datos");
        btnActualizarDatos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnActualizarDatosActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtFiltro, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 178, Short.MAX_VALUE)
                                .addComponent(btnActualizarDatos))
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 499, Short.MAX_VALUE)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(95, 95, 95)
                        .addComponent(pnlInscripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(txtFiltro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnActualizarDatos, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(14, 14, 14)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(pnlInscripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(84, 84, 84))
        );

        jTabbedPane1.addTab("Buscar Partidas", jPanel3);

        txtJugadorBlancas.setEditable(false);

        txtJugadorNegras.setEditable(false);

        txtNombreTorneo.setEditable(false);

        jLabel1.setText("Jugador Blancas:");

        jLabel2.setText("Jugador Negras:");

        jLabel3.setText("Nombre de Torneo:");

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jtpMovimientos.setEditable(false);
        jScrollPane1.setViewportView(jtpMovimientos);

        lblMovimientos.setText("Movimientos:");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(lblMovimientos)
                .addContainerGap())
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(lblMovimientos)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE))
        );

        jLabel8.setText("Fecha de Juego: ");

        rbtBlancas.setText("Ganan Blancas");
        rbtBlancas.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        rbtBlancas.setMargin(new java.awt.Insets(0, 0, 0, 0));

        rbtNegras.setText("Ganan Negras");
        rbtNegras.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        rbtNegras.setMargin(new java.awt.Insets(0, 0, 0, 0));

        lblSexo.setText("Resultado:");

        btnActualizarPartida.setText("Actualizar datos");
        btnActualizarPartida.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnActualizarPartidaActionPerformed(evt);
            }
        });

        btnLimpiar.setText("Limpiar");
        btnLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimpiarActionPerformed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel7.setText("(*)");

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel12.setText("(*)");

        jLabel15.setText("Datos Obligatorios");

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel14.setText("(*)");

        rbtTablas.setText("Tablas");
        rbtTablas.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        rbtTablas.setMargin(new java.awt.Insets(0, 0, 0, 0));

        btnBlancas.setText("...");
        btnBlancas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBlancasActionPerformed(evt);
            }
        });

        btnNegras.setText("...");
        btnNegras.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNegrasActionPerformed(evt);
            }
        });

        btnTorneo.setText("...");
        btnTorneo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTorneoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel3)
                            .addComponent(jLabel8)
                            .addComponent(jLabel2)
                            .addComponent(lblSexo))
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(rbtBlancas)
                            .addComponent(rbtNegras)
                            .addComponent(rbtTablas)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jdcFechaJuego, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(txtNombreTorneo, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtJugadorNegras, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtJugadorBlancas, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(btnTorneo)
                                    .addGroup(jPanel4Layout.createSequentialGroup()
                                        .addComponent(btnNegras)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel7))
                                    .addGroup(jPanel4Layout.createSequentialGroup()
                                        .addComponent(btnBlancas)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel12)))))
                        .addGap(4, 4, 4)
                        .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 499, Short.MAX_VALUE)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(btnLimpiar)
                        .addGap(15, 15, 15)
                        .addComponent(btnActualizarPartida)
                        .addGap(195, 195, 195)
                        .addComponent(jLabel14)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel15)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(txtJugadorBlancas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(btnBlancas)
                                .addComponent(jLabel12))
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(txtJugadorNegras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(btnNegras)
                                .addComponent(jLabel7))
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(txtNombreTorneo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnTorneo))
                        .addGap(9, 9, 9)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel8)
                            .addComponent(jdcFechaJuego, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(rbtBlancas)
                            .addComponent(lblSexo))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rbtNegras)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rbtTablas)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnActualizarPartida)
                    .addComponent(btnLimpiar)
                    .addComponent(jLabel15)
                    .addComponent(jLabel14))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Editar Partida", jPanel4);

        btnSalir.setText("Salir");
        btnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 524, Short.MAX_VALUE)
                    .addComponent(btnSalir))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(15, Short.MAX_VALUE)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnSalir))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnTorneoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTorneoActionPerformed
// TODO add your handling code here:
        frmElegirTorneo fet = new frmElegirTorneo(this);
        this.jDesktopPane1.add(fet);
        fet.setVisible(true);
    }//GEN-LAST:event_btnTorneoActionPerformed

    private void btnNegrasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNegrasActionPerformed
// TODO add your handling code here:
        frmElegirJugadores fej = new frmElegirJugadores(this, "negro");
        this.jDesktopPane1.add(fej);
        fej.setVisible(true);
    }//GEN-LAST:event_btnNegrasActionPerformed

    private void btnBlancasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBlancasActionPerformed
// TODO add your handling code here:
        frmElegirJugadores fej = new frmElegirJugadores(this, "blanco");
        this.jDesktopPane1.add(fej);
        fej.setVisible(true);
    }//GEN-LAST:event_btnBlancasActionPerformed

    private void btnLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimpiarActionPerformed
// TODO add your handling code here:
        this.limpiarDatos();
    }//GEN-LAST:event_btnLimpiarActionPerformed

    private void btnActualizarPartidaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnActualizarPartidaActionPerformed
// TODO add your handling code here:
        boolean resultado;
        String resultadoPartida = "1-0";
        int elegido = 0;
        unaPartida.setNombreJugadorBlanco(this.txtJugadorBlancas.getText());
        unaPartida.setNombreJugadorNegro(this.txtJugadorNegras.getText());
        unaPartida.setFechaJuego(this.jdcFechaJuego.getCalendar());

        if (this.jugadorBlancas != null) {
            unaPartida.setIdJugadorBlancas(this.jugadorBlancas.getIdJugador());
        }
        if (this.jugadorNegras != null) {
            unaPartida.setIdJugadorNegras(this.jugadorNegras.getIdJugador());
        }
        if (this.miTorneo != null) {
            unaPartida.setIdTorneo(this.miTorneo.getIdTorneo());
        }

        if (this.rbtBlancas.isSelected() == true) {
            resultadoPartida = "1-0";
        } else if (this.rbtNegras.isSelected() == true) {
            resultadoPartida = "0-1";
        } else if (this.rbtTablas.isSelected() == true) {
            resultadoPartida = "1/2-1/2";
        }
        unaPartida.setResultado(resultadoPartida);

        if (this.txtJugadorBlancas.getText().trim().length() == 0) {
            JOptionPane.showMessageDialog(this, "Ponga al jugador de Piezas Blancas, Por favor", "Informacion", JOptionPane.WARNING_MESSAGE);
        } else if (this.txtJugadorNegras.getText().trim().length() == 0) {
            JOptionPane.showMessageDialog(this, "Ponga al jugador de Piezas Negras, Por favor", "Informacion", JOptionPane.WARNING_MESSAGE);
        } else {
            resultado = this.pBL.actualizarPartida(unaPartida.dameIdPartida(), unaPartida);
            if (resultado == true) {
                JOptionPane.showMessageDialog(this, "Se ha actualizado correctamente", "Informacion", JOptionPane.INFORMATION_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(this, "Ha Ocurrido un error. No se han grabado los datos", "Informacion", JOptionPane.INFORMATION_MESSAGE);
            }
            this.limpiarDatos();
            llenarGrillaPartidas();
            this.btnBlancas.setEnabled(false);
            this.btnNegras.setEnabled(false);
            this.btnTorneo.setEnabled(false);
            this.btnActualizarPartida.setEnabled(false);
        }

    }//GEN-LAST:event_btnActualizarPartidaActionPerformed

    private void btnActualizarDatosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnActualizarDatosActionPerformed
// TODO add your handling code here:
        int fila, id;
        int indiceTablaOrdenada;
        jTabbedPane1.setSelectedIndex(1);

        fila = this.tblPartidas.getSelectedRow();

        if (fila >= 0) {
            indiceTablaOrdenada = tblPartidas.convertRowIndexToModel(fila);
            unaPartida = this.arrPartidas.get(indiceTablaOrdenada);
            id = unaPartida.dameIdPartida();
            unaPartida = this.damePartidadeLista(this.arrPartidas, id);
            this.txtJugadorBlancas.setText(unaPartida.dameNombreJugadorBlanco());
            this.txtJugadorNegras.setText(unaPartida.dameNombreJugadorNegro());
            this.txtNombreTorneo.setText(unaPartida.dameNombreTorneo());
            this.jdcFechaJuego.setCalendar(unaPartida.dameFechaJuego());
            this.jtpMovimientos.setText(unaPartida.dameMovimientos());

            this.btnBlancas.setEnabled(true);
            this.btnNegras.setEnabled(true);
            this.btnTorneo.setEnabled(true);
            this.btnActualizarPartida.setEnabled(true);

            if (unaPartida.dameResultado().equals("1-0") == true) {
                this.rbtBlancas.setSelected(true);
            } else if (unaPartida.dameResultado().equals("0-1") == true) {
                this.rbtNegras.setSelected(true);
            } else {
                this.rbtTablas.setSelected(true);
            }
        }
    }//GEN-LAST:event_btnActualizarDatosActionPerformed

    private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalirActionPerformed
// TODO add your handling code here:
        this.dispose();
}//GEN-LAST:event_btnSalirActionPerformed

    private void tblPartidasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblPartidasMouseClicked
// TODO add your handling code here:
        fila = this.tblPartidas.getSelectedRow();
        //unaPartida = this.arrPartidas.get(fila);
        String strIndice = this.tblPartidas.getValueAt(fila, 0).toString();
        idPartidaElegida = Integer.parseInt(strIndice);

        //System.out.println("QQQQQ: "+idPartidaElegida);        
        if (fila >= 0) {
            this.btnVerPartida.setEnabled(true);
    }//GEN-LAST:event_tblPartidasMouseClicked

 }

private void btnVerPartidaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVerPartidaActionPerformed
// TODO add your handling code here:
        unaPartida = this.pBL.getPartidaxId(this.idPartidaElegida);
        try {
            frmLecturaPartidas flp = new frmLecturaPartidas(unaPartida);
            this.jDesktopPane1.add(flp);
            flp.setVisible(true);
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
            ex.printStackTrace();
        }    
}//GEN-LAST:event_btnVerPartidaActionPerformed

    
/*Martes 09 de octubre del 2007. 10:22 pm. Caballo Viejo*/   
    private partida damePartidadeLista(ArrayList<partida> arrPartida, int id) {
        for (partida p : arrPartida) {
            if (p.dameIdPartida() == id) {
                return p;
            }
        }
        return null;
    }

    private void searchFieldChangedUpdate(DocumentEvent evt) {
        try {
            text = this.txtFiltro.getText();
            if (text.length() == 0) {
                sorter.setRowFilter(null);
            } else {
                try {
                    sorter.setRowFilter(RowFilter.regexFilter("(?i)" + text));
                } catch (PatternSyntaxException e) {
                    e.printStackTrace();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    void limpiarDatos() {
        this.txtJugadorBlancas.setText("");
        this.txtJugadorNegras.setText("");
        this.txtNombreTorneo.setText("");
    }

    public void dameJugadorBlancas(jugador unJugador) {
        this.jugadorBlancas = unJugador;
        String nombres = unJugador.getApellidoPaterno() + ", " + unJugador.getNombres();
        this.txtJugadorBlancas.setText(nombres);
    }

    public void dameTorneo(torneo unTorneo) {
        this.miTorneo = unTorneo;
        this.txtNombreTorneo.setText(miTorneo.getnombreTorneo());
    }

    public void dameJugadorNegras(jugador unJugador) {
        this.jugadorNegras = unJugador;
        String nombres = unJugador.getApellidoPaterno() + ", " + unJugador.getNombres();
        this.txtJugadorNegras.setText(nombres);
    }

    public void llenarGrillaPartidas() {
        int id, ano, mes, dia;
        jugador player;
        arrPartidas = new ArrayList<partida>();

        Vector rows = new Vector();
        for (partida pBE : this.pBL.getLstPartidas()) {
            arrPartidas.add(pBE);

            Vector row = new Vector();

            row.add(pBE.dameIdPartida());

            ano = pBE.dameFechaJuego().get(Calendar.YEAR);
            mes = pBE.dameFechaJuego().get(Calendar.MONTH) + 1;
            dia = pBE.dameFechaJuego().get(Calendar.DATE);
            row.add(ano + "/" + mes + "/" + dia);

            row.add(pBE.dameNombreJugadorBlanco());
            row.add(pBE.dameNombreJugadorNegro());
            row.add(pBE.dameNombreTorneo());
            row.add(pBE.dameResultado());

            rows.add(row);
        }

        Vector colNames = new Vector();
        for (int i = 0; i < this.tblPartidas.getColumnCount(); i++) {
            colNames.add(this.tblPartidas.getColumnName(i));
        }

//        dtm = new DefaultTableModel(rows,colNames);
        dtm = new DefaultTableModel(rows, colNames) {
//            public Class getColumnClass(int col){
//                switch (col) {
//                    case 4: return Boolean.class;
//                    default: return Object.class;
//                }
//            }

            public boolean isCellEditable(int row, int column) {
//                return column == 4;
                return false;

            }
        };

        sorter = new TableRowSorter(dtm);
//        sorter.setRowFilter(RowFilter.regexFilter(text);
        this.tblPartidas.setModel(dtm);
        this.tblPartidas.setRowSorter(sorter);

//        TableColumnModel tcm = tblPartidas.getColumnModel();
//        tcm.getColumn(0).setPreferredWidth(20);
//        tcm.getColumn(1).setPreferredWidth(100);        
//        tcm.getColumn(4).setPreferredWidth(20);    
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnActualizarDatos;
    private javax.swing.JButton btnActualizarPartida;
    private javax.swing.JButton btnBlancas;
    private javax.swing.JButton btnLimpiar;
    private javax.swing.JButton btnNegras;
    private javax.swing.JButton btnSalir;
    private javax.swing.JButton btnTorneo;
    private javax.swing.JButton btnVerPartida;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private com.toedter.calendar.JDateChooser jdcFechaJuego;
    private javax.swing.JTextPane jtpMovimientos;
    private javax.swing.JLabel lblMovimientos;
    private javax.swing.JLabel lblSexo;
    private javax.swing.JPanel pnlInscripcion;
    private javax.swing.JRadioButton rbtBlancas;
    private javax.swing.JRadioButton rbtNegras;
    private javax.swing.JRadioButton rbtTablas;
    private javax.swing.JTable tblPartidas;
    private javax.swing.JTextField txtFiltro;
    private javax.swing.JTextField txtJugadorBlancas;
    private javax.swing.JTextField txtJugadorNegras;
    private javax.swing.JTextField txtNombreTorneo;
    // End of variables declaration//GEN-END:variables
}
